﻿<div class="easyui-layout" data-options="fit: true">
    <div data-options="region: 'center', border: false" style="padding:10px; overflow: hidden;">
        <!--表单-->
        <div class="panel-default p10" data-options="region:'north',border: false,split:true" style="height:120px;">
            <div class="form-inline">
                <form id="commonStockInFromValidate" name="commonStockInFromValidate" onsubmit="return false;">
                    <table class="line30td" width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                            <tr>
                                <td class="t_r wd70">单据编号：</td>
                                <td class="t_l wd200"><input id="orderId" name="orderId" class="form-control input-xs wd200" type="text" disabled="disabled" data-options="required:true,prompt:'单据编号'" value="@(ViewBag.NextId)"></td>
                                <td class="t_r wd70"></td>
                                <td class="t_l wd200"></td>
                                <td class="t_r wd70"><span class="red">*</span>容器编码：</td>
                                <td class="t_l wd200">
                                    <select id="containerCode" name="containerCode" class="easyui-combobox wd200" data-options="valueField:'id',textField:'name',required:true,prompt:'容器编码'"></select>
                                    <script type="text/javascript">
                                        $(function () {
                                            //获取控件
                                            var containerCode = $("#containerCode").comboselect({
                                                onDialog: function (target) {

                                                    window.Topro.DAO.Container({
                                                        title: '容器',
                                                        isSingle: true,
                                                        selectingData: [],
                                                        saveCallBack: function (res) {
                                                            var list = $(containerCode).comboselect("getData");

                                                            list.push({
                                                                id: res.code,
                                                                name: res.code
                                                            });

                                                            $(containerCode).combobox('loadData', list);
                                                            $(containerCode).combobox("setValue", res.code);
                                                        }
                                                    });

                                                }
                                            });
                                        });
                                    </script>
                                </td>
                                <td class="t_r wd70"></td>
                                <td class=""></td>
                            </tr>
                            <tr>
                                <td class="t_r wd70">入库库位：</td>
                                <td class="t_l wd200">
                                    <select id="warehouseUnitId" name="warehouseUnitId" class="easyui-combobox wd200" data-options="valueField:'id',textField:'name',prompt:'入库库位'"></select>
                                    <script type="text/javascript">
                                        $(function () {
                                            //获取控件
                                            var warehouseUnitId = $("#warehouseUnitId").comboselect({
                                                onDialog: function (target) {
                                                    Topro.DAO.WarehouseUnit({
                                                        title: '库位',
                                                        isSingle: true,
                                                        selectingData: [],
                                                        saveCallBack: function (res) {

                                                            var list = $(warehouseUnitId).comboselect("getData");

                                                            list.push({
                                                                id: res.id,
                                                                name: "{0}-{1}-{2}".format(res.pai, res.lie, res.ceng)
                                                            });

                                                            $(warehouseUnitId).combobox('loadData', list);

                                                            $(warehouseUnitId).combobox("setValue", res.id);
                                                        }
                                                    });
                                                }
                                            });

                                        });
                                    </script>
                                </td>
                                <td class="t_r wd70"></td>
                                <td class="t_l wd200"></td>
                                <td class="t_r wd70">站台：</td>
                                <td class="t_l wd200">
                                    <input maxlength="30" class="easyui-validatebox form-control input-xs wd200" type="text" id="stationNo" name="stationNo" autocomplete="off" data-options="prompt:'站台'">
                                </td>
                            </tr>
                            <tr>
                                <td class="t_r wd70">备注：</td>
                                <td class="t_l wd200">
                                    <input maxlength="30" class="easyui-validatebox form-control input-xs wd200" type="text" id="remark" name="remark" autocomplete="off" data-options="prompt:'备注'">
                                </td>
                                <td class="t_r wd70">&nbsp;</td>
                                <td class="t_l wd200">&nbsp;</td>
                                <td class="t_r wd70">&nbsp;</td>
                                <td class="t_l wd200"><span class="abs_r mt5 mr5"><a class="btn btn-primary btn-xs" style="height:23px;" onclick="return page.selectProductStockIn();"><span class="iconfont icon-anonymous-iconfont f12 "></span>选择物料</a></span></td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!--列表-->
        <div class="tabtool">
            <span class="abs_r mt5 mr5"><a class="btn btn-primary btn-xs" style="height:23px;" onclick="return page.selectProductStockIn();"><span class="iconfont icon-anonymous-iconfont f12 "></span>选择物料</a></span>
        </div>
        <div data-options="region:'center',split: false, border: false">
            <table id="commonStockInDG"></table>
        </div>
    </div>
</div>
<div id="menu" class="easyui-menu">
    <div onclick="page.delete()" data-options="iconCls:'icon-add'">删除</div>
</div>
<script type="text/javascript">
    //定义
    var commonStockInDG = $('#commonStockInDG');

    $(function () {
        Topro.UI.DataGrid(commonStockInDG, {
            fit: true,
            method: "get",
            url: "@Url.Action("ProductEmptyQuery", "Module")",
            queryParams: {},
            idField: 'id',
            remoteSort: false,
            multiSort: false,
            pagination: true,
            singleSelect: false,
            rownumbers: true,   //行号
            frozenColumns: [
                [
                    { field: 'ck', checkbox: true }
                ]
            ],
            columns: [
                [
                    {
                        field: 'name',
                        title: '物料名称',
                        width: 150,
                        editor: {
                            type: 'comboselect',
                            options: {
                                textField: 'Pname',
                                valueField: 'Pvalue',
                                method: 'get',
                                url: '@Url.Action("ProductCategorys", "Common")',
                                required: false,
                                onDialog: function (target) {

                                    window.Topro.DAO.Product({
                                        title: '物料',
                                        isSingle: true,
                                        saveCallBack: function (updateRow) {
                                            var row = commonStockInDG.datagrid('getSelected');
                                            if (row) {
                                                var rowIndex = commonStockInDG.datagrid('getRowIndex', row);
                                                if (rowIndex < 0) {
                                                    window.top.$.messager.alert('提示', '请选择删除行.', 'info');
                                                }

                                                commonStockInDG.datagrid('updateRow', {
                                                    index: rowIndex,
                                                    row: updateRow
                                                })
                                            }
                                        }
                                    });

                                },
                                onSelect: function () {

                                }
                            }
                        }
                    },
                    {
                        field: 'lotNo',
                        title: '批号',
                        width: 300,
                        align: 'left',
                        editor: {
                            type: 'text',
                            options: {
                                required: true
                            }
                        }
                    },
                    {
                        field: 'quantity',
                        title: '数量',
                        width: 75,
                        align: 'center',
                        editor: {
                            type: 'text',
                            options: {
                                required: true
                            }
                        }
                    },
                    {
                        field: 'code',
                        title: '条码 ',
                        width: 100
                    },
                    {
                        field: 'status',
                        title: '商品编码',
                        align: 'center',
                        width: 100
                    }
                ]
            ],
            rowTooltip: false,
            onRowContextMenu: function (e, rowIndex, rowData) {
                //阻止浏览器自带的右键菜单弹出
                e.preventDefault();
                //选中当前行
                $(this).datagrid('selectRow', rowIndex);
                //弹出窗口的方位坐标
                $('#menu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            }
        });
    });

    var page = {
        delete: function () {
            var row = commonStockInDG.datagrid('getSelected');
            if (row) {
                var rowIndex = commonStockInDG.datagrid('getRowIndex', row);
                if (rowIndex < 0) {
                    window.top.$.messager.alert('提示', '请选择删除行.', 'info');
                }

                commonStockInDG.datagrid('deleteRow', rowIndex);
            } else {
                window.top.$.messager.alert('提示', '请选择删除行.', 'info');
                return;
            }
        },
        queryParams: function () {
            var params = {
            };

            return params;
        },
        selectProductStockIn: function () {
            Topro.DAO.Product({
                title: '物料',
                isSingle: false,
                saveCallBack: function (rows) {
                    debugger
                    if (rows.length <= 0) {
                        Topro.UI.Prompt({ content: '请选择物料.', type: 'info' });
                        return;
                    } else {
                        $.each(rows, function (i, row) {

                            //数量
                            row.quantity = 1;

                            commonStockInDG.datagrid('insertRow', {
                                index: 1,
                                row: row
                            })
                        });
                    }

                    return;
                }
            });
        },
        doSearch: function () {
            //绑定


        }
    }
</script>
